<template>
	<view class="page" :style="{paddingTop:navHeight + 'px' }">
		<view class="page2">
			<view class="big-title">
				请选择您的行业类别
			</view>
			<view class="btm-title">
				<span style="color: #B81E1E;">*</span>行业类别可选择多个
			</view>
			<view class="select-wrap" v-for="(item,index) in hyList">
				<view class="select-label">
					{{item.hyflName}}
				</view>
				<view class="select-list">
					<view class="select-option" @click="selectAll(index)" :class="item.check?'active':''">
						选择全部
					</view>
					<view class="select-option" :class="type.check?'active':''" v-for="(type,typeIndex) in item.data"
						@click="selectType(index,typeIndex)">
						{{type.typeName}}
					</view>
				</view>
			</view>
			<view class="btm-wrap-tc">

			</view>
			<view class="btm-wrap">
				<view class="btn confim-btn" @click="submit">
					完成
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navHeight: 0,
				navIndex: 0,
				hyList: [],
				type: ''


			};
		},
		onLoad(option) {
			uni.getSystemInfo({
				success: (data) => {
					let custom = wx.getMenuButtonBoundingClientRect()
					//导航栏高度 = 状态栏到胶囊的间距（胶囊距上距离-状态栏高度） * 2 + 胶囊高度 + 状态栏高度。
					this.navHeight = custom.bottom + custom.top - data.statusBarHeight
				}
			})
			if (option.type) {
				this.type = option.type
				this.toNext()
			}
		},
		methods: {
			submit() {
				let list = [],
					listName = []
				for (let i = 0; i < this.hyList.length; i++) {
					for (let ii = 0; ii < this.hyList[i].data.length; ii++) {
						if (this.hyList[i].data[ii].check) {
							list.push(this.hyList[i].data[ii].id)
							listName.push(this.hyList[i].data[ii].typeName)
						}
					}
				}
				if (list.length === 0) {
					uni.showToast({
						title: "请至少选中一项行业分类",
						icon: "none"
					})
				}
				this.$api.member.saveHangye({
					hyfl: list.join(','),
					hyflInfo: listName.join(','),
					type: this.type
				}).then(res => {
					uni.navigateBack()
				})
			},
			back() {
				this.hyList = []
				this.navIndex = 0
			},
			selectAll(idx) {
				if (this.hyList[idx].check) {
					this.hyList[idx].check = false
				} else {
					this.hyList[idx].check = true
				}
				for (let i = 0; i < this.hyList[idx].data.length; i++) {
					this.hyList[idx].data[i].check = this.hyList[idx].check
				}
				this.$forceUpdate()
			},
			testAll(idx) {
				let flag = true
				for (let i = 0; i < this.hyList[idx].data.length; i++) {
					if (!this.hyList[idx].data[i].check) {
						flag = false
					}
				}
				this.hyList[idx].check = flag
			},
			selectType(idx, idxx) {
				if (this.hyList[idx].data[idxx].check) {
					this.hyList[idx].data[idxx].check = false
				} else {
					this.hyList[idx].data[idxx].check = true
				}
				this.$forceUpdate()
				this.testAll(idx)
			},
			toNext() {
				this.$api.company.getHylbList({
					type: this.type
				}).then(res => {
					this.hyList = res.data
					this.$api.member.getMemberInfo().then(res => {
						if (res.data.member.hyfl) {
							let hyfl = res.data.member.hyfl.split(',')
							console.log('hyfl',hyfl);
							for (let iii = 0; iii < hyfl.length; iii++) {
								for (let i = 0; i < this.hyList.length; i++) {
									for (let ii = 0; ii < this.hyList[i].data.length; ii++) {
										if (this.hyList[i].data[ii].id == hyfl[iii]) {
											this.hyList[i].data[ii].check = true
										}
									}
								}
							}
						}
						this.$forceUpdate()


					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding-left: 40rpx;
		padding-right: 40rpx;
		background-color: #fff;

		>view {
			width: 100%;
			padding-top: 44rpx;
		}

		.big-title {
			font-weight: bold;
			font-size: 40rpx;
			line-height: 56rpx;
		}

		.mid-title {
			font-weight: bold;
			font-size: 28rpx;

		}

		.btm-title {
			font-size: 28rpx;
			color: #777777;

		}

		.page2 {
			.btm-title {
				margin-bottom: 66rpx;
			}

			.select-wrap {
				margin-bottom: 42rpx;

				.select-label {
					font-weight: bold;
					font-size: 32rpx;
					margin-bottom: 24rpx;
				}

				.select-list {
					overflow: hidden;
					width: 100%;

					.select-option {
						width: auto;
						height: 60rpx;
						border-radius: 36rpx;
						border: 1px solid #D9D9D9;
						padding: 0 20rpx;
						margin-right: 20rpx;
						margin-bottom: 22rpx;
						float: left;
						line-height: 58rpx;

						&.active {
							background: #EC2424;
							border: 1px solid #EC2424;
							color: #FFFFFF;
						}
					}
				}
			}
		}

		.page1 {
			.list {
				width: 100%;
				box-shadow: 0px 0 26rpx 0px rgba(0, 0, 0, 0.06);
				height: 226rpx;
				margin-bottom: 40rpx;
				padding: 0 40rpx 0 68rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.tx {
					width: 176rpx;
					height: 176rpx;
				}

				.btn {
					width: 198rpx;
					height: 72rpx;
					background: #F0F0F0;
					border-radius: 36rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 28rpx;
					font-weight: bold;
				}
			}
		}

		.btm-wrap-tc {
			width: 100%;
			height: 180rpx;

		}

		.btm-wrap {
			width: 100%;
			position: fixed;
			bottom: 96rpx;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.btn {
				width: 244rpx;
				height: 70rpx;
				border-radius: 42rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;

				&.return-btn {
					border: 1px solid #EC2424;
					color: #EC2424;
					background-color: #FFFFFF;
				}

				&.confim-btn {
					color: #FFFFFF;
					background: #EC2424;
				}
			}
		}
	}
</style>